<?php namespace App\Weixin;

use App\Weixin\Repositories\MenuRepositories;
class Menus{

    public function __construct() {

    }

    /**
     * 新增菜单
     * @param array $data
     * @return bool
     */
    public  static function addMenu(array $data) {
        try {
            $menu = MenuRepositories::create($data);
            return $menu->id;
        } catch(\Exception $e) {
            // 存储报错
            return false;
        }
    }

    /**
     *
     * @param array $data
     * @param $id
     */
    public static function updateMenu(array $data, $id) {
        try {
            $menu = MenuRepositories::where('id', $id)->update($data);
            return $menu;
        } catch(\Exception $e) {
            // 存储报错
            return false;
        }
    }

    /**
     * 删除菜单
     * @param $id 菜单ID
     */
    public static function deleteMenu($id) {
        try {
            $menu = MenuRepositories::where('id', $id)->delete();
            return $menu;
        } catch(\Exception $e) {
            // 存储报错
            return false;
        }
    }

    /**
     * 获取菜单列表
     * @return mixed
     */
    public static function getMenuList() {
        return MenuRepositories::orderBy('menuvalue')->get();
    }

    /**
     * 获取菜单详细信息
     * @param $id
     */
    public static function getMenuDetail($id) {
        return MenuRepositories::find($id);
    }

    /**
     * 获取一级菜单
     */
    public static function getHeadMenu() {
        return MenuRepositories::where('belongto',0)->get();
    }
}